package com.hunanwenli.service.impl;
import com.hunanwenli.service.RedisService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;
import java.util.concurrent.TimeUnit;

/**
 * @author wanzhenyu
 * @date 2021/6/5 19:32
 */
@Service
public class RedisServiceImpl implements RedisService {

    @Autowired
    private RedisTemplate<Object,Object> redisTemplate;
    @Override
    public void put(String key, String value) {
        redisTemplate.opsForValue().set(key,value);

    }

    @Override
    public void put(String key, String value, Long time) {
        redisTemplate.opsForValue().set(key,value,time, TimeUnit.SECONDS);
    }

    @Override
    public String get(String key) {
        return (String) redisTemplate.opsForValue().get(key);
    }

    @Override
    public void setList(String redisKey, List<String> listToken,Long time) {
       redisTemplate.opsForList().leftPushAll(redisKey,listToken.toArray());
       redisTemplate.expire(redisKey,time,TimeUnit.SECONDS);
    }

    @Override
    public Object popList(String redisKey) {
        return redisTemplate.opsForList().rightPop(redisKey);
    }


}
